//
//  LKAddShopViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/5/28.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKAddShopViewController.h"
#import <UFKit/UFKit.h>
#import "LKShopInformationViewController.h"
#import "LKOpenShopStepOneViewController.h"

@interface LKAddShopViewController ()

@property(nonatomic,strong)UFFormView *formView;

@end

@implementation LKAddShopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    WS(weakSelf)
    self.navigationItem.title = @"新增商户";
    self.formView = [UFFormView makeFormView:^(UFFormViewMaker * _Nonnull make) {
        make
        .addSection([UFSection makeSection:^(UFSectionMaker * _Nonnull make) {
            make
            .titleStyle([UFRowTitleStyle makeTitleStyle:^(UFRowTitleStyleMaker * _Nonnull make) {
               make
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor)
                .textAlignment(NSTextAlignmentLeft);
            }])
            .valueStyle([UFTextStyle makeTextStyle:^(UFRowTextStyleMaker * _Nonnull make) {
                make
                .textAlignment(NSTextAlignmentRight)
                .font([UIFont fontWithName:@"PingFangSC-Regular" size:16])
                .color(labelBlackColor);
                
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"商户全称")
                .name(@"merchant_name")
                .value(@"");
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"商户手机号")
                .name(@"user_phone")
                .value(@"");
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .height(RowHeightDefault)
                .title(@"登录密码")
                .name(@"pwd")
                .value(@"123456");
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .editable(NO)
                .height(RowHeightDefault)
                .title(@"推荐人")
                .name(@"referrer")
                .value([LKUserInforTool account].user_phone);
            }]);
        }])
        .addToSuperView(self.view);
    }];
    LKBaseButton *protocalBtn = [LKBaseButton buttonWithFrame:CGRectZero type:UIButtonTypeCustom title:@" 立即帮商户提交资料" titleColor:yellowDefaultColor layercorne:0 font:[UIFont fontWithName:@"PingFangSC-Regular" size:12] backgroudColor:[UIColor clearColor] AndActionBlock:^(UIButton * _Nonnull btn) {
        btn.selected = !btn.selected;
    }];
    [protocalBtn setImage:[UIImage imageNamed:@"xuanzhong_customer"] forState:UIControlStateNormal];
    [protocalBtn setImage:[UIImage imageNamed:@"weixuanzhong_customer"] forState:UIControlStateSelected];
    [self.view addSubview:protocalBtn];
    LKBaseButton *submmitBtn = [LKBaseButton buttonWithFrame:CGRectZero type:UIButtonTypeCustom title:@"确认添加账号" titleColor:[UIColor whiteColor] layercorne:25 font:[UIFont fontWithName:@"PingFangSC-Medium" size:18] backgroudColor:yellowDefaultColor AndActionBlock:^(UIButton * _Nonnull btn) {
        NSMutableDictionary *param = (NSMutableDictionary *)[self.formView toDictionary];
        [param setObject:[LKUserInforTool account].token forKey:@"token"];
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyShopOpenAddUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            if ([responseObject[@"code"] isEqualToString:@"success"]) {
                if (!protocalBtn.selected) {
                    LKOpenShopStepOneViewController *vc = [[LKOpenShopStepOneViewController alloc] init];
                    vc.uid = responseObject[@"uid"];
                    vc.fee_type = responseObject[@"fee_type"];
                    vc.merchant_name = param[@"merchant_name"];
                    [self.navigationController pushViewController:vc animated:YES];
                }else{
                    [self.navigationController popViewControllerAnimated:YES];
                }

            }else{
                [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
            }

        } failure:^(NSString * _Nullable errorMessage) {
            
        }];
    }];
    [self.view addSubview:submmitBtn];
    [self.formView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view).mas_equalTo(NAVIGATION_BAR_HEIGHT + 10);
        make.height.mas_equalTo(208);
    }];
    self.formView.scrollEnabled = NO;
    [protocalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(20);
        make.top.equalTo(_formView.mas_bottom).offset(10);
    }];
    [submmitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(protocalBtn.mas_bottom).offset(28);
        make.left.equalTo(self.view).offset(10);
        make.height.mas_equalTo(50);
        make.centerX.equalTo(self.view);
    }];
    // Do any additional setup after loading the view.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
